package com.zwh.modules.goods.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.zwh.autoconfigure.rabbitmq.DirectExchangeConfig;

/**
 * @author monkey
 * @date 2020/11/6 15:42
 **/
@Service
public class MessageSender {
    private static Logger log = LoggerFactory.getLogger(MessageSender.class);
    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 发送秒杀消息
     * @param userBuyGoodsMessage
     */
    public void sendSecondKillMessage(UserBuyGoodsMessage userBuyGoodsMessage) {
        String msg = JSONObject.toJSONString(userBuyGoodsMessage);
        log.info("send message:"+msg);
        rabbitTemplate.convertAndSend(DirectExchangeConfig.SECONDKILL_EXCHANGE, DirectExchangeConfig.SECONDKILL_QUEUE, msg);
    }
}
